package com.elinkway.infinitemovies.http.requesttask;

import android.content.Context;

import com.elinkway.infinitemovies.async.MoviesHttpAsyncTask;
import com.elinkway.infinitemovies.async.RequestResultListener;
import com.elinkway.infinitemovies.bean.CommonBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.CommonParser;
import com.lvideo.http.bean.LVideoDataHull;

import org.json.JSONObject;

import java.util.List;

/**
 * Author: liuxiaojiang(xiao)
 * Date: 2017-07-07
 * Time: 19:23
 * Description: FIXME
 */
public class OnePointReportTask extends MoviesHttpAsyncTask<CommonBean> {
    private JSONObject jsonObject;

    private RequestResultListener<CommonBean> mListener;

    public RequestResultListener<CommonBean> getmListener() {
        return mListener;
    }

    public void setmListener(RequestResultListener<CommonBean> mListener) {
        this.mListener = mListener;
    }

    @Override
    public void netNull() {
        if(null != mListener){
            mListener.onRequestFailed();
        }
        super.netNull();
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        if(null != mListener){
            mListener.onRequestFailed();
        }
        super.netErr(updateId, errMsg);
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        if(null != mListener){
            mListener.onRequestFailed();
        }
        super.dataNull(updateId, errMsg);
    }

    public OnePointReportTask(Context context, JSONObject jsonObject) {
        super(context);
        this.jsonObject = jsonObject;
    }

    @Override
    public LVideoDataHull<CommonBean> doInBackground() {
        LVideoDataHull<CommonBean> ret = MoviesHttpApi.onePointReport(
                new CommonParser(), jsonObject);
        return ret;
    }

    @Override
    public void onPostExecute(int updateId, CommonBean result) {
        if(null != mListener){
            mListener.onRequestSuccess(updateId, result);
        }
    }
}
